package cn.edu.xmu.restfuldemo.model.VO;

import cn.edu.xmu.restfuldemo.model.BO.Goods;
import cn.edu.xmu.restfuldemo.model.BO.OrderItem;
import cn.edu.xmu.restfuldemo.model.BO.Orders;
import cn.edu.xmu.restfuldemo.model.BO.Product;
import cn.edu.xmu.restfuldemo.model.PO.OrdersPo;
import cn.edu.xmu.restfuldemo.model.VoObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单对象
 * @author Team3-5
 **/
@Data
@ApiModel(description = "订单对象")
@Getter
@Setter
@AllArgsConstructor
@ToString
public class OrdersRetVo implements VoObject {

    private Long id;
    private String orderSn;
    private Long pid;
    private Byte orderType;
    private Byte state;
    private Byte subState;
    private Long originPrice;
    private Long discountPrice;
    private Long freightPrice;
    private Integer rebateNum;
    private String message;
    private Long regionId;
    private String address;
    private String mobile;
    private String consignee;
    private Long couponId;
    private Long grouponId;
    private Long presaleId;
    private String shipmentSn;
    private LocalDateTime confirmTime;
    private LocalDateTime gmtCreate;
    private LocalDateTime gmtModified;
    private List<OrderItemRetVo>orderItems;

    public OrdersRetVo(){
        orderItems = new ArrayList<>();
    }

    public OrdersRetVo(Orders orders, List<OrderItem>list) {
        this.id = orders.getId();
        this.orderSn = orders.getOrderSn();
        this.pid = orders.getPid();
        this.orderType = orders.getOrderType();
        this.state = orders.getState();
        this.subState = orders.getSubstate();
        this.originPrice = orders.getOriginPrice();
        this.discountPrice = orders.getDiscountPrice();
        this.freightPrice = orders.getId();
        this.rebateNum = orders.getRebateNum();
        this.message = orders.getMessage();
        this.regionId = orders.getRegionId();
        this.address = orders.getAddress();
        this.mobile = orders.getMobile();
        this.consignee = orders.getConsignee();
        this.couponId = orders.getCouponId();
        this.grouponId = orders.getGrouponId();
        this.presaleId = orders.getPresaleId();
        this.shipmentSn = orders.getShipmentSn();
        this.confirmTime = orders.getConfirmTime();
        this.gmtCreate = orders.getGmtCreate();
        this.gmtModified = orders.getGmtModified();
        List<OrderItemRetVo>orderItems = new ArrayList<>();
        for(OrderItem orderItem:list){
            orderItems.add(new OrderItemRetVo(orderItem));
        }
        this.orderItems = orderItems;
    }

    /**
     * OrdersRetVo->Orders
     * @return
     */
    public Orders newOrdersFromOrdersRetVo(){
        Orders orders= new Orders();
        orders.setId(this.id);
        orders.setOrderSn(this.orderSn);
        orders.setPid(this.pid);
        orders.setConsignee(this.consignee);
        orders.setRegionId(this.regionId);
        orders.setAddress(this.address);
        orders.setMobile(this.mobile);
        orders.setMessage(this.message);
        orders.setOrderType(this.orderType);
        orders.setFreightPrice(this.freightPrice);
        orders.setCouponId(this.couponId);
        orders.setDiscountPrice(this.discountPrice);
        orders.setOriginPrice(this.originPrice);
        orders.setPresaleId(this.presaleId);
        orders.setRebateNum(this.rebateNum);
        orders.setConfirmTime(this.confirmTime);
        orders.setShipmentSn(this.shipmentSn);
        orders.setState(this.state);
        orders.setGmtCreate(this.gmtCreate);
        orders.setGmtModified(this.gmtModified);
        orders.setGrouponId(this.grouponId);
        return orders;
    }

    public List<OrderItem> newOrderItemList(){
        if(this.orderItems==null){
            this.orderItems = new ArrayList<>();
        }
        List<OrderItem>orderItems = new ArrayList<>();
        for(OrderItemRetVo orderItemRetVo:this.orderItems){

        }
        return orderItems;
    }
    @Override
    public Object createVo() {
        return this;
    }

    @Override
    public Object createSimpleVo() {
        return this;
    }
}
